import { asyncRoutes, constantRoutes } from '@/router'
import store from '@/store'
const state = {
  // 用于渲染页面的菜单栏
  routes: []
}
const mutations = {
  // 修改routes
  setRoutes(state, data) {
    state.routes = [...constantRoutes, ...data]
  }
}
const actions = {
  filtersRoutes() {
    const menus = store.state.user.profile.roles.menus
    // 过滤当前账号权限（过滤掉当前账号没有的权限）
    const routes = asyncRoutes.filter(item => menus.includes(item.name))
    // 修改 routes
    store.commit('permission/setRoutes', routes)
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
